home *** CD-ROM | disk | FTP | other *** search
- Path: prodigy.com!usenet
- From: XKWR65B@prodigy.com (Mark Rubelmann)
- Newsgroups: comp.lang.c++
- Subject: How do you return values from in-line asm?
- Date: 26 Mar 1996 21:07:23 GMT
- Organization: Prodigy Services Company 1-800-PRODIGY
- Distribution: world
- Message-ID: <4j9mab$19si@usenetp1.news.prodigy.com>
- NNTP-Posting-Host: innugap8-int.news.prodigy.com
- X-Newsreader: Version 1.2
-
-
- Hey there! I got this book that is about programming games in C but I
- have Borland C++ v3.0 and some of the stuff doesn't work quite right.
- Most of the things I have been able to figure out on my own but I'm
- having trouble returning values from an inline assembly function. Here's
- the code that's in the book:
-
- unsigned char Get_Scan_Code(void)
- {
- asm {
- mov ah,01h //Function 1: is a key ready?
- int 16h // Call interrupt
- jz empty // No key, exit
- mov ah,00h // Function 0: get scan code
- int 16h // Call interrupt
- mov al,ah // result was in ah so put it in al
- xor ah,ah // zero out ah
- jmp done // the data's in ax (??? ax???)
-
- empty:
- xor ax,ax // clear out ax, 0 means no key
- done:
- }
- }
-
-
- First of all, I just don't understand how the resut went from al to ax.
- Also, I know the line labels should be outside of the asm statement but
- that's the way it was in the book. I've tried fooling around with ret and
- stuff like that but I can't get it to work. The compiler always gives a
- warning that it should return a value. When I try to use the function in
- something like:
-
- while(Get_Scan_Code==0) {}
-
- but it doesn't work, it just goes on to the next statement. Any help
- would be appreciated.
-
-
-